from django.db import models


class ChartConfig(models.Model):
    """图表配置模型"""
    student = models.ForeignKey('users.Student', on_delete=models.CASCADE, related_name="chart_configs")
    chart_type = models.CharField(max_length=50, verbose_name="图表类型",
                                  choices=[('line', '折线图'), ('bar', '柱状图'), ('radar', '雷达图'),('pie','饼图')])
    subjects = models.ManyToManyField('score.Subject', verbose_name="显示科目")
    time_range = models.CharField(max_length=20, verbose_name="时间范围",
                                  choices=[('7d', '近7天'), ('30d', '近30天'), ('all', '全部')])
    show_trend_line = models.BooleanField(default=True, verbose_name="显示趋势线")
    show_confidence_band = models.BooleanField(default=False, verbose_name="显示置信带")
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = "图表配置"
        verbose_name_plural = "图表配置"
        unique_together = ['student', 'chart_type']

    def __str__(self):
        return f"{self.student.name} - {self.chart_type}"
